package com.xiaxinyu.mango.controller;


import com.xiaxinyu.mango.entity.Customer;
import com.xiaxinyu.mango.repository.CustomerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;

/**
 * @author XIAXINYU3
 * @date 2021/5/13
 */
@RestController
@RequestMapping("/v1")
public class MongoController {

    @Autowired
    private CustomerRepository customerRepository;

    @Autowired
    private MongoTemplate mongoTemplate;


    /**
     * 处理excel与数据库之间的差异数据
     */
    @RequestMapping("/customer/list")
    public List<Customer> dobegin() throws Exception {
        int a = Math.abs(new Random().nextInt()) ;
        Customer customer = new Customer();
        customer.set_id(String.valueOf(a));
        customer.setCarNumber("card-" + a);
        customerRepository.insert(customer);

        List<Customer> list = customerRepository.findAll();
        return list;
    }
}